import { history } from 'umi';

export function handleLogout() {
  sessionStorage.removeItem('login');
  history.push('login');
  console.log('登出');
}

export function formatTime(time: string, type: 'FULL_TIME' | 'ONLY_DAY') {
  const date = new Date(Number(time));
  const year = date.getFullYear();
  const month = (date.getMonth() + 1).toString().padStart(2, '0');
  const day = date.getDate().toString().padStart(2, '0');
  const hour = date.getHours().toString().padStart(2, '0');
  const minute = date.getMinutes().toString().padStart(2, '0');
  const second = date.getSeconds().toString().padStart(2, '0');
  const onlyDay = `${year}-${month}-${day}`;
  const fullTime = `${onlyDay} ${hour}:${minute}:${second}`;
  if (type === 'FULL_TIME') {
    return fullTime;
  } else {
    return onlyDay;
  }
}
